
const mysql = require('mysql');
const dbconfig = require('../config/dbconfig.js')
const connection = mysql.createConnection(dbconfig);

//连接mysql
connection.connect(function (err) {
    if (err) {
        console.error('连接失败');
        return;
    }
    console.log('连接mysql成功');
});


 //成功调用resolve 
 //错误调用reject
function dbQuery(sql){
    return new Promise((resolve,reject)=>{
        connection.query(sql,(err,result)=>{
            if(err){
                reject(err)
            }else{
                resolve(result)
            }
        })
    })
}


module.exports = dbQuery;